# --*-- coding : utf-8 --*--
# --*-- author : silly rabbit --*--

import requests
from bs4 import BeautifulSoup

# 类
class Douban:
    def __init__(self):
        # 爬虫的url
        self.URL = 'https://movie.douban.com/top250'
        # 每一页的开始序号
        self.starnum =[]
        for start_num in range(0,251,25):
            self.starnum.append(start_num)
        # 浏览器头部
        self.header = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36'}

    def get_top250(self):
        # 设置每一页的开始序号
        for start in self.starnum:
            start = str(start)
            # 将html的参数补上
            html = requests.get(self.URL, params={'start':start},headers = self.header)
            # 获取html文本
            soup = BeautifulSoup(html.text,"html.parser")
            # 选择电影名称
            name = soup.select('#content > div > div.article > ol > li > div > div.info > div.hd > a > span:nth-child(1)')
            # 将电影名称用文本打印出来
            for name in name:
                print(name.get_text())

if __name__== "__main__":
    # 生成一个实例
    cls = Douban()
    # 获取数据
    cls.get_top250()